//
//  ViewController.m
//  WuShiCity
//
//  Created by chengjie on 16/7/4.
//  Copyright © 2016年 chengjie. All rights reserved.
//

#import "ViewController.h"


@interface ViewController ()
{
    
    UITabBarController *tabBar;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    设置导航栏的颜色
    [UINavigationBar appearance].barTintColor=[UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    
    _homePageVC = [[HomePageViewController alloc]init];
    _findVC = [[FindViewController alloc]init];
    _publishVC = [[PublishViewController alloc]init];
    _messageVC = [[MessageViewController alloc]init];
    _personalCenterVC = [[PersonalCenterViewController alloc]init];
    //    tabbar选中时的字体颜色
    [self setUpOneChildViewController:_homePageVC];
    [self setUpOneChildViewController:_findVC];
    [self setUpOneChildViewController:_publishVC];
    [self setUpOneChildViewController:_messageVC];
    [self setUpOneChildViewController:_personalCenterVC];
    
    _homePageVC.title=@"首页";
    _findVC.title=@"发现";
    _publishVC.title=@"发布";
    _messageVC.title=@"消息";
    _personalCenterVC.title=@"个人中心";
    
    _homePageVC.tabBarItem.image = [UIImage imageNamed:@"红色要闻"];
    _homePageVC.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"红色要闻"];
    _findVC.tabBarItem.image = [UIImage imageNamed:@"灰色友情链接"];
    _findVC.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"红色友情链接"];
    _publishVC.tabBarItem.image = [UIImage imageNamed:@"红色动态"];
    _publishVC.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"红色动态"];
    _messageVC.tabBarItem.image = [UIImage imageNamed:@"红色公益"];
    _messageVC.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"红色公益"];
    _personalCenterVC.tabBarItem.image = [UIImage imageNamed:@"红色文明办"];
    _personalCenterVC.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"红色文明办"];
    //导航状态
    UINavigationController *firstNav=[[UINavigationController alloc]initWithRootViewController:_homePageVC];
    UINavigationController *secondNav=[[UINavigationController alloc]initWithRootViewController:_findVC];
    UINavigationController *thirdNav=[[UINavigationController alloc]initWithRootViewController:_publishVC];
    UINavigationController *fourthNav=[[UINavigationController alloc]initWithRootViewController:_messageVC];
    UINavigationController *fifthNav=[[UINavigationController alloc]initWithRootViewController:_personalCenterVC];
    //改变导航条的图片
//      [secondNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forBarMetrics:UIBarMetricsDefault];
    firstNav.tabBarItem.title = @"首页";
    secondNav.tabBarItem.title = @"发现";
    thirdNav.tabBarItem.title = @"发布";
    fourthNav.tabBarItem.title = @"消息";
    fifthNav.tabBarItem.title = @"个人中心";
    
    
    //    设置tabbar的子视图控制器
    
    tabBar.viewControllers=@[firstNav,secondNav,thirdNav,fourthNav,fifthNav];
    UIWindow *window=[UIApplication sharedApplication].delegate.window;
    window.rootViewController=tabBar;
    
    // Do any additional setup after loading the view, typically from a nib.
}

//设置tabbar选中时的字体颜色
- (void)setUpOneChildViewController:(UIViewController *)viewController{
    
    tabBar=[[UITabBarController alloc]init];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];
    [_homePageVC.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    return  [viewController.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
